1 #pragma warning (disable:4786)
2 #pragma warning (disable:4996)
20 #define REP(i,n) for(i=1; i<=(n); i++)
21 #define REPO(i,n) for(int i=0; i<(n); i++)
22 #define REPA(i,a,b) for(i=a; i<=(b); i++)
23 #define min(a,b) ((a) < (b) ? (a) : (b))
24 #define max(a,b) ((a) > (b) ? (a) : (b))
25 #define init(a) (memset(a,0,sizeof(a)))
29 freopen("test.in","rt",stdin
);
30 freopen("test.out","wt",stdout
);
45 memset(number
,0,sizeof(number
));
54 // takes 'r' as right number and writes result to 'this'
56 HugeInt
* operator= (const HugeInt
* r
) {
57 memset(number
,0,sizeof(number
));
58 strcpy(number
,r
->number
);
64 HugeInt
* operator= (const int r
) {
65 memset(number
,0,sizeof(number
));
66 sprintf(number
,"%d",r
);
67 length
= strlen(number
);
68 for (int i
= 0; i
< (length
>> 1); i
++) {
70 number
[i
] = number
[length
-i
-1];
71 number
[length
-i
-1] = c
;
73 for (int j
= 0; j
< length
; j
++)
79 const HugeInt
operator+ (const HugeInt
& r
) {
80 int n
= max(length
,r
.length
), carry
= 0, k
, i
;
82 for (i
= 0; i
< n
|| carry
; i
++) {
83 k
= number
[i
] + r
.number
[i
] + carry
;
84 theNew
.number
[i
] = k
% 10;
92 void operator+= (const HugeInt
& r
) {
96 // *slightly veryfied*
97 const HugeInt
operator* (const int r
) {
100 for (i
= 0; i
< length
|| carry
; i
++) {
101 k
= number
[i
] * r
+ carry
;
102 theNew
.number
[i
] = k
% 10;
109 // *slightly veryfied*
110 void operator*= (const int r
) {
115 // shifts number left by 'shift' positions
116 // useful when multiplying two HugeInt's
117 HugeInt
operator<< (const int shift
) {
120 // don't shift if number is 0 and there is no number
121 //if (length == 0 || length == 1 && number[0] == 0) return;
122 for (i
= length
- 1; i
>= 0; i
--)
123 theNew
.number
[i
+ shift
] = number
[i
];
124 for (i
= 0; i
< shift
; i
++)
125 theNew
.number
[i
] = 0;
126 theNew
.length
= length
+ shift
;
130 HugeInt
operator* (HugeInt
& r
) {
133 for (i
= 0; i
< length
; i
++)
134 theNew
+= (r
<< i
) * number
[i
];
139 HugeInt
operator*= (HugeInt
& r
) {
144 int operator % (int r
) {
146 for (int i
= length
- 1; i
>= 0; i
--)
147 n
= (n
* 10 + number
[i
]) % r
;
151 int operator %= (int r
) {
155 HugeInt
operator/ (int r
) {
159 for (int i
= length
- 1; i
>= 0 || n
>= r
; i
--) {
160 n
= (n
* 10 + number
[i
]);
161 I
.number
[j
++] = n
/ r
;
166 for (int i
= 0; i
< j
/ 2; i
++)
167 swap(I
.number
[i
],I
.number
[j
-i
-1]);
174 HugeInt
operator /= (int r
) {
181 for (int i
= length
- 1; i
>= 0; i
--)
182 putchar(number
[i
] + '0');
185 void truncate(HugeInt
& n
) {
186 for (int i
= n
.length
- 1; i
>= 0 && n
.number
[i
] == 0; i
--)
194 HugeInt
power(int p
) {
196 for (int i
= 0; i
< p
; i
++)
201 bool operator<(const HugeInt
& rhs
) {
202 if (this->length
!= rhs
.length
)
203 return this->length
< rhs
.length
;
204 for (int i
= 0; i
< this->length
; i
++)
205 if (this->number
[i
] != rhs
.number
[i
])
206 return this->number
[i
] < rhs
.number
[i
];
211 if (length
== 1 && number
[0] == 0) {
219 int M
[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
225 for (int i
= 1; i
<= 2000; i
++) {
229 if (!DP
[i
- M
[0]][0].isnull())
230 DP
[i
][0] += DP
[i
- M
[0]][0];
231 if (!DP
[i
- M
[0]][1].isnull())
232 DP
[i
][0] += DP
[i
- M
[0]][1];
234 for (int j
= 1; j
< 10; j
++) if (i
- M
[j
] >= 0) {
235 if (!DP
[i
- M
[j
]][0].isnull())
236 DP
[i
][1] += DP
[i
- M
[j
]][0];
237 if (!DP
[i
- M
[j
]][1].isnull())
238 DP
[i
][1] += DP
[i
- M
[j
]][1];
250 for (int i
= 1; i
<= 2000; i
++) {
251 A
[i
] = A
[i
- 1] + DP
[i
][1];
252 //cout << A[i].length << endl;
258 if (scanf("%d",&n
) != 1)